package com.cn.jdia.tas.module;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DetailCheckInfo {
	private String name;
	private String id;
	private List<CheckInfoModule> list;
	private List<String> dateList;

	public DetailCheckInfo() {
		list = new ArrayList<CheckInfoModule>();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<CheckInfoModule> getList() {
		return list;
	}

	public void setList(List<CheckInfoModule> list) {
		this.list = list;
	}

	public void addChild(CheckInfoModule child) {
		list.add(child);
	}

	public String getFirstCheckTime(String date) {
		if (list.size() == 0) {
			return "";
		}
		Iterator<CheckInfoModule> it = list.iterator();
		String tmp = "24:00";
		while (it.hasNext()) {
			CheckInfoModule module = it.next();
			if (!module.getDate().equals(date)) {
				continue;
			}

			String time = module.getTime();
			if (time.compareTo(tmp) < 0) {
				tmp = time;
			}
		}
		return tmp;
	}

	public String getLastCheckTime(String date) {
		if (list.size() <= 1) {
			return "";
		}
		Iterator<CheckInfoModule> it = list.iterator();
		String tmp = "00:00";
		while (it.hasNext()) {
			CheckInfoModule module = it.next();
			if (!module.getDate().equals(date)) {
				continue;
			}

			String time = module.getTime();
			if (time.compareTo(tmp) > 0) {
				tmp = time;
			}
		}
		if (tmp.equals(getFirstCheckTime(date))) {
			return "";
		}
		return tmp;
	}

	public List<String> getDateList() {
		dateList = new ArrayList<String>();
		Iterator<CheckInfoModule> it = list.iterator();
		while (it.hasNext()) {
			CheckInfoModule info = it.next();
			String data = info.getDate();

			if (!dateList.contains(data)) {
				dateList.add(data);
			} else {
				continue;
			}
		}
		return dateList;
	}

	public String getPersonId() {
		if (list.size() != 0) {
			String personId = list.get(0).getId();
			return personId;
		} else
			return null;
	}

	public String getPersonName() {
		if (list.size() != 0) {
			String personName = list.get(0).getName();
			return personName;
		} else
			return null;
	}
}
